/*
 * Checkbox.cpp
 *
 *  Created on: 24/07/2013
 *      Author: vitor
 */

#include "Checkbox.h"

Checkbox::Checkbox(Point position, bool selected) {
	_position = position;
	_selected = selected;
	_selectedSprite = new Sprite("../gfx/checkBoxSelector.png");
	_checkBoxContainerSprite = new Sprite("../gfx/checkBoxContainer.png");

	_containerBox.x = position.getX()
			- _checkBoxContainerSprite->getWidth() / 2;
	_containerBox.y = position.getY()
			- _checkBoxContainerSprite->getHeight() / 2;
	_containerBox.w = _checkBoxContainerSprite->getWidth();
	_containerBox.h = _checkBoxContainerSprite->getHeight();
}

Checkbox::~Checkbox() {
	delete (_selectedSprite);
	delete (_checkBoxContainerSprite);
}

void Checkbox::update() {
	if (InputManager::getInstance()->isMouseDown(SDL_BUTTON_LEFT)) {
		if (InputManager::getInstance()->isMouseInside(&_containerBox)) {
			_selected = !_selected;
		}
	}

	if (_selected) {
		_selectedSprite->setHidden(false);
	} else {
		_selectedSprite->setHidden(true);
	}
}

void Checkbox::render(float cameraX, float cameraY) {
	_checkBoxContainerSprite->render(_position.getX() - cameraX,
			_position.getY() - cameraY, true);
	_selectedSprite->render(_position.getX() - cameraX,
			_position.getY() - cameraY, true);
}
